/**
*
* @author 
*
*/
class MyUtils {
    public constructor() {
    }

    static GetBtn(w: number,h: number,cx: number,cy: number,img: string): egret.Sprite {
        var spr1: egret.Sprite = new egret.Sprite();
        spr1.graphics.beginFill(0x00ff00,0);
        spr1.graphics.drawRect(0,0,w,h);
        spr1.graphics.endFill();
        spr1.width = w;
        spr1.height = h;
        spr1.x = cx;
        spr1.y = cy;
        spr1.touchEnabled = true;
        spr1.addChild(MyUtils.createBitmapByName(img));
        return spr1;
    }

    static GetBtn1(w: number,h: number,cx: number,cy: number,alpha:number=0): egret.Sprite {
        var spr1: egret.Sprite = new egret.Sprite();
        spr1.graphics.beginFill(0x000000,alpha);
        spr1.graphics.drawRect(0,0,w,h);
        spr1.graphics.endFill();
        spr1.width = w;
        spr1.height = h;
        spr1.x = cx;
        spr1.y = cy;
        spr1.touchEnabled = true;
        return spr1;
    }
    static GetTextField(size: number,cx: number,cy: number,wi: number = 100,he: number = 45,Mutil: boolean = false): egret.TextField {
        var tx: egret.TextField = new egret.TextField;
        // this.addChild(this._name);
        tx.x = cx;
        tx.y = cy;
        //   this._name.type = egret.TextFieldType.INPUT;
        tx.textAlign = egret.HorizontalAlign.CENTER;
        tx.fontFamily = "微软雅黑";
        tx.textColor = 0xFFFFFF;
        tx.width = wi;
        tx.height = he;
        tx.multiline = Mutil;
        tx.size = size;
        tx.text = "";
        return tx;
    }
    //影片对象
    static createMovieClipByName(namse: string): egret.MovieClip {
        var spr1: egret.MovieClip = new egret.MovieClip();
        var data = RES.getRes(namse + "_json");
        var texture = RES.getRes(namse + "_png");
        var mcDataFactory: egret.MovieClipDataFactory = new egret.MovieClipDataFactory(data,texture);
        spr1 = new egret.MovieClip(mcDataFactory.generateMovieClipData(namse));
        return spr1;
    }
    //影片获取
     static createMovieClipByName2(json: string,png:string,mc:string): egret.MovieClip {
        var spr1: egret.MovieClip = new egret.MovieClip();
        var data = RES.getRes(json);
        var texture = RES.getRes(png);
        var mcDataFactory: egret.MovieClipDataFactory = new egret.MovieClipDataFactory(data,texture);
        spr1 = new egret.MovieClip(mcDataFactory.generateMovieClipData(mc));
        return spr1;
    }
    /**
    * 根据name关键字创建一个Bitmap对象。name属性请参考resources/resource.json配置文件的内容。
    * Create a Bitmap object according to name keyword.As for the property of name please refer to the configuration file of resources/resource.json.
    */
    static createBitmapByName(name: string,anchorOffset:number=1): egret.Bitmap {
        var result: egret.Bitmap = new egret.Bitmap();
        var texture: egret.Texture = RES.getRes(name);
        result.texture = texture;
        result.anchorOffsetX
        switch(anchorOffset){
            case 0:
            result.anchorOffsetX=result.width/2;
            result.anchorOffsetY=result.height/2;
            break;
            case 8:
            result.anchorOffsetX=result.width/2;
            result.anchorOffsetY=result.height;
            break;
        }
        return result;
    }
    //
    //纹理集
    static createSpriteSheetByName(json: string,frames: string): egret.Bitmap {
        var result: egret.Bitmap = new egret.Bitmap();
        var imgs: egret.SpriteSheet = RES.getRes(json);
        result.texture = imgs.getTexture(frames);
        return result;
    }
    //
    static getMyParamer(param) {
        var oRequest = new Object();
        oRequest = MyUtils.GetRequest();
        return oRequest[param];
    }
    static GetRequest() {

        var url = document.location.search; //获取url中"?"符后的字串
        var theRequest = new Object();
        if(url.indexOf("?") != -1) {
            var str = url.substr(1);
            var strs = str.split("&");
            for(var i = 0;i < strs.length;i++) {
                theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }
    static  createTextField(_width: number, _heigth: number, _size: number, _color: number, _str: string, _type: string = egret.TextFieldType.DYNAMIC, _format: string = egret.HorizontalAlign.LEFT, _multiline: boolean = false): egret.TextField {
        var label: egret.TextField = new egret.TextField();
        label.type = _type;
        label.multiline = _multiline;
        label.textColor = _color;
        label.size = _size;
        label.textAlign = _format;
        label.width = _width;
        label.height = _heigth;
        label.text = _str;
        return label;
    };
}
